#!/usr/bin/env python
# encoding: utf-8
"""
test.py

Created by AlanYang on 2011-06-17.
Copyright (c) 2011 __MyCompanyName__. All rights reserved.
"""

import sys
import os
import types
import xapian
from multiprocessing import Process
from application import app
#insert db.set_document(doc)
#remove db.delete_document(did)
#find   db.get_document(did)
#update db.replace_document(did,newdoc)

def main():
    db = xapian.WritableDatabase('/Users/apple/Project/xapiandb',xapian.DB_OPEN)
    doc = db.get_document(2)
    print doc.get_data()
    doc.set_data("""Created by AlanYang on 2011-06-17...""")
    db.replace_document(2,doc)
    db.commit()
    db.flush()

def job():
    """docstring for job"""
    print 10

def __is_string__(s):
    """docstring for __is_string__"""
    try:
        s + ''
        return True
    except:
        return False
         
def __flat__(field):
    result = []
    if type(field) == types.ListType:
        for i in field:
            if not __is_string__(i):
                result.extend(__flat__(i))
            else:
                result.append(i)
    elif type(field) == types.DictType:
        for k,v in field.items():
            if not __is_string__(v):
                result.extend(__flat__(v))
            else:
                result.append(v)
    return result   
    
if __name__ == '__main__':
    print __flat__({'a':['1','2','3','4',['5','6','7',['8',['9']]]],'b':'123123123','c':{'as':'56767','213':{'asd':'123123'}}})
    
